//
//  RCtabBarButton.m
//  RCsinaMicroBlog
//
//  Created by Mr.Ray on 15/1/29.
//  Copyright (c) 2015年 Ray.peng. All rights reserved.
//

#import "RCtabBarButton.h"

@implementation RCtabBarButton


- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

// 通过xib/Storboard创建时调用
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setItem:(UITabBarItem *)item{
    _item = item;
    [self setTitle:item.title forState:UIControlStateNormal];    
    [self setImage:item.image forState:UIControlStateNormal];
    [self setImage:item.selectedImage forState:UIControlStateSelected];

}
- (void)setup{
    
    self.imageView.contentMode = UIViewContentModeCenter;
    
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    self.titleLabel.font = [UIFont systemFontOfSize:13];
    
    
    //设置标题颜色
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    
    CGFloat imageX = 0;
    CGFloat imageY = 3;
    CGFloat imageH = contentRect.size.height *0.6;
    CGFloat imageW = contentRect.size.width;
    
    return CGRectMake(imageX, imageY, imageW, imageH);
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    
    CGFloat titleX = 0;
    CGFloat titleY = contentRect.size.height *0.6;
    CGFloat titleH = contentRect.size.height -contentRect.size.height*0.6;
    CGFloat titleW = contentRect.size.width;
    return CGRectMake(titleX, titleY, titleW, titleH);
    
}

- (void)setHighlighted:(BOOL)highlighted{
    
}

@end
